<?php
use Yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;
use backend\assets\AppAsset;
$this->title = '网站公告管理';
?>
<div class="container">
    <div class="row">
      
        <?php echo $this->render('_leftnav'); ?>

        <div class="col-md-10">
          <div class="page-header clearfix">
            <h1 class="pull-left">网站公告管理</h1>
            <div class="pull-right">

                                                                      <a class="btn btn-success btn-sm" data-url="/admin/announcement/create" data-toggle="modal" data-target="#modal">新增公告</a>

                                                
            </div>
          </div>

	        <div aria-hidden="false" style="display: none;" id="modal" class="modal in"><div class="modal-dialog ">
			        <div class="modal-content">
				        <div class="modal-header">
					        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					        <h4 class="modal-title">新增公告</h4>
				        </div>
				        <div class="modal-body">
<!--					        <form data-widget-cid="widget-0" novalidate="novalidate" id="announcement-create-form" class="form-horizontal" method="post" action="/app.php/admin/announcement/create">-->
					        <!--站点配置表单类-->
					        <?php
					        $form = ActiveForm::begin([
						        'options' => ['class' => 'form-horizontal','id'=>'announcement-create-form'],
						        'action'=>Url::to(['operate/webnoticeadd']),
						        'method'=>'post',
					        ]);
					        ?>

					        <?= $form->field($model, 'site_notice',['template'=>'<div class="row form-group"><div class="col-md-2 control-label">{label}</div><div class="col-md-8 controls">{input}{error}<div class="help-block" style="display:none;"></div></div></div>'])->textInput(['maxlength' => 150]) ?>



				        </div>
				        <div class="modal-footer">
<!--					        <button id="announcement-create-btn" data-submiting-text="正在提交" type="submit" class="btn btn-primary pull-right" data-toggle="form-submit" data-target="#announcement-create-form">提交</button>-->
					        <?= Html::submitButton('提交', ['class'=>'btn btn-primary pull-right','id' =>'announcement-create-btn']) ?>
<!--					        <button type="button" class="btn btn-link pull-right" data-dismiss="modal">取消</button>-->
					        <?= Html::resetButton('取消', ['class'=>'btn btn-link pull-right','data-dismiss'=>'modal']) ?>
					        <?php ActiveForm::end();?>
					        <script>app.load('announcement/create-modal')</script>
				        </div>
			        </div>
		        </div></div>
          
                              
          
          
        <table id="announcement-table" class="table table-striped">
          <thead>
            <tr>
              <th width="85%">公告内容</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
          <?php foreach($data as $k=>$v){ ?>
	          <tr>
	              <td><?= Html::encode($v['config_value'])?></td>
	              <td>
		              <div class="btn-group">
		                 <a data-url="/admin/announcement/edit/1" class="btn btn-default btn-sm noticeupd" data-toggle="modal" data-target="#noticeupd" val="<?= Html::encode($v['config_id'])?>">编辑</a>
		                 <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
			                <span class="caret"></span>
	                     </a>
	                     <ul class="dropdown-menu">
	                        <li><a href="javascript::" data-url="/admin/announcement/delete/1" class="delete-btn noticedel" val="<?= Html::encode($v['config_id'])?>"><span class="glyphicon glyphicon-trash"></span> 删除</a></li>

	                     </ul>
	                  </div>
	            </td>
	          </tr>
          <?php } ?>
        </tbody>
        </table>
        </div>
    </div>
</div>
<div id="noticeupd" class="modal fade"></div>
<script>
	$(".noticeupd").click(function(){
		var config_id=$(this).attr("val");
		$.ajax({
			type: "POST",
			url: "<?php echo  \Yii::$app->urlManager->createUrl('operate/webnoticeupd') ?>",
			data: "config_id="+config_id,
			success: function(msg){
				$("#noticeupd").html(msg);
			}
		});
	})
	$(".noticedel").click(function(){
		if(confirm("确定要删除此公告吗？")){
			var config_id = $(this).attr("val");
			$.ajax({
				type: "POST",
				url: "<?php echo  \Yii::$app->urlManager->createUrl('operate/webnoticedel') ?>",
				data: "config_id="+config_id,
				success: function(msg){
					if(msg == 1)
					{
						location.reload();
					}else if(msg == 0)
					{
						alert('删除失败');
					}else
					{
						alert('没有传值')
					}

				}
			});
		}
	})
</script>
